require "./SysT2.css"
{Srv} = require "Srv"
{SysWin} = require "./SysWin"

SuperClzz = SysWin
exports["@SysT2"] = {comment:"标签页面基类"}
exports.SysT2 = new Class
  Extends: SuperClzz
  options:
    enyStr: "Emp"
    #父页面选中的行对应的实体类
    sld_eny: {}
  onDraw: ->
    t = this
    o = t.options
    elt = o.ele
    rv = yield SuperClzz.prototype.onDraw.apply t,arguments
    yield t.hInclude()
    t.initPrnWin()
    rv
  initPrnWin: ->
    t = this
    o = t.options
    elt = o.ele
    prnWin = elt.getE "[h:include]>[h:pg]"
    if prnWin
      prnWinWg = prnWin.wg()
      trSld = prnWinWg.trSld
      prnWinWg.trSld = (tr)->
        hsChg = yield trSld.apply prnWinWg,arguments
        yield t.prn_trSld prnWin,tr if hsChg
        hsChg
    return
  "@prn_trSld":{comment:"父页面的表格选中一行"}
  prn_trSld: (prnWin,tr)->
    t = this
    o = t.options
    elt = o.ele
    return if !tr
    prnWinWg = prnWin.wg()
    prnWinOp = prnWinWg.options
    o.sld_eny = prnWinOp.sld_eny
    sld_eny = tr.retrieve "eny"
    winArr = elt.getEs "[h:include]>[h:pg]"
    for win,i in winArr
      continue if i is 0
      winWg = win.wg()
      if !tr
        yield winWg.emptyGrid()
        continue
      #给子页面强制增加筛选条件,用于跟父页面的外键关联
      yield o.thisSrv.ajax "prn_trSld",[sld_eny]
      yield winWg.dataCount()
      yield winWg.firstPgClk undefined,undefined,true
    return
  initThisSrv: ->
    t = this
    o = t.options
    elt = o.ele
    clz = "sys."+o.enyStr+"T2Srv"
    
    prnClz = ""
    prnWinArr = elt.getParents "[h:pg]"
    for i in [0...prnWinArr.length]
      prnWin = prnWinArr[prnWinArr.length-1-i]
      continue if prnWin is document.body
      prnPg = prnWin.get "h:pg"
      prnClz += prnPg+"."
    clz = prnClz+clz+"||"+clz if prnClz
    
    o.thisSrv = new Srv clz:clz
    o.thisSrv.options.ele = elt
    return
  initPg: ->
    t = this
    o = t.options
    elt = o.ele
    return
